﻿'Copyright (C) 2010  Thomas Huebner
'
'This program is free software
'
'you can redistribute it and/or modify it under the terms 
'of the GNU General Public License as published by the 
'Free Software Foundation either version 2 of the License, 
'or (at your option) any later version.
'
'This program is distributed in the hope that it will be 
'useful, but WITHOUT ANY WARRANTY without even the implied 
'warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
'See the GNU General Public License for more details.
'
'You should have received a copy of the GNU General Public License 
'along with this program; if not, write to the 
'Free Software Foundation, Inc., 59 Temple Place, Suite 330, 
'Boston, MA 02111-1307, USA. 


Imports System.Xml.Serialization
Imports System.IO
Imports System.Text
Imports System.ComponentModel


Public Class LF_AreaListConverter
    '''
    ''' <summary>Read a String to LF_AreaList object </summary>
    ''' <param name="text" >XML Source as string</param>
    ''' <returns>LF_AreaList object</returns>
    '''
    Public Shared Function ReadAreaList(ByVal text As String) As LF_AreaList
        Dim xs As New XmlSerializer(GetType(LF_AreaList))
        Dim tr As TextReader = New StringReader(text)
        Return DirectCast(xs.Deserialize(tr), LF_AreaList)
    End Function

    '''
    ''' <summary>Write an LF_AreaList object to XML string</summary>
    ''' <param name="oLF_AreaList" >LF_AreaList object</param>
    ''' <returns>XML Source as string</returns>
    '''
    Public Shared Function WriteAreaList(ByVal oLF_AreaList As LF_AreaList) As String
        Dim xs As New XmlSerializer(GetType(LF_AreaList))
        Dim sb As New StringBuilder()
        Dim tw As TextWriter = New StringWriter(sb)
        xs.Serialize(tw, oLF_AreaList)
        Return tw.ToString
    End Function

End Class

<XmlRoot("area_list")> _
Public Class LF_AreaList

    <XmlNamespaceDeclarations()> _
        Public namespaces As XmlSerializerNamespaces

    <XmlAttribute("version")> _
        Public version As String

    <XmlElement("area")> _
        Public items As LF_Area()

End Class


''' <summary>
''' This class reflect a single Area
''' </summary>
''' <remarks></remarks>
<XmlRoot("area")> _
Public Class LF_Area

    <EditorBrowsable(EditorBrowsableState.Never)> _
    <XmlElement("id")> _
        Public _ID As String

    ''' <summary>
    ''' Id of the suggestion
    ''' </summary>
    ''' <value></value>
    ''' <returns>Integer</returns>
    ''' <remarks></remarks>
    <XmlIgnore()> _
    Public ReadOnly Property ID() As Integer
        Get
            If Not String.IsNullOrEmpty(Me._ID) Then
                Return CInt(Me._ID)
            Else
                Return 0
            End If
        End Get
    End Property


    <EditorBrowsable(EditorBrowsableState.Never)> _
    <XmlElement("name")> _
        Public _Name As String

    ''' <summary>
    ''' Name of the Area.
    ''' </summary>
    ''' <value></value>
    ''' <returns>Integer</returns>
    ''' <remarks></remarks>
    <XmlIgnore()> _
    Public ReadOnly Property Name() As String
        Get
            If Not String.IsNullOrEmpty(Me._Name) Then
                Return Me._Name.Trim
            Else
                Return String.Empty
            End If
        End Get
    End Property


    <EditorBrowsable(EditorBrowsableState.Never)> _
    <XmlElement("description")> _
        Public _Description As String

    ''' <summary>
    ''' Description of the Area.
    ''' </summary>
    ''' <value></value>
    ''' <returns>Integer</returns>
    ''' <remarks></remarks>
    <XmlIgnore()> _
    Public ReadOnly Property Description() As String
        Get
            If Not String.IsNullOrEmpty(Me._Description) Then
                Return Me._Description
            Else
                Return String.Empty
            End If
        End Get
    End Property


    <EditorBrowsable(EditorBrowsableState.Never)> _
    <XmlElement("direct_member_count")> _
        Public _DirectMemberCount As String

    ''' <summary>Number of direct members</summary>
    ''' <value></value>
    ''' <returns>Integer</returns>
    ''' <remarks></remarks>
    <XmlIgnore()> _
    Public ReadOnly Property DirectMemberCount() As Integer
        Get
            If Not String.IsNullOrEmpty(Me._DirectMemberCount) Then
                Return CInt(Me._DirectMemberCount)
            Else
                Return 0
            End If
        End Get
    End Property


    <EditorBrowsable(EditorBrowsableState.Never)> _
    <XmlElement("member_weight")> _
        Public _MemberWeight As String

    ''' <summary>
    ''' Number of members including membership via delegation.
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    <XmlIgnore()> _
    Public ReadOnly Property MemberWeight() As Integer
        Get
            If Not String.IsNullOrEmpty(Me._MemberWeight) Then
                Return CInt(Me._MemberWeight)
            Else
                Return 0
            End If
        End Get
    End Property


    <EditorBrowsable(EditorBrowsableState.Never)> _
    <XmlElement("autoreject_weight")> _
        Public _AutoRejectWeight As String

    ''' <summary>
    ''' Number of members using autoreject in this area (including delegted weight).
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    <XmlIgnore()> _
    Public ReadOnly Property AutoRejectWeight() As Integer
        Get
            If Not String.IsNullOrEmpty(Me._AutoRejectWeight) Then
                Return CInt(Me._AutoRejectWeight)
            Else
                Return 0
            End If
        End Get
    End Property


    <EditorBrowsable(EditorBrowsableState.Never)> _
    <XmlElement("active")> _
        Public _Active As String

    ''' <summary>
    ''' True if this area is still in use, false if not.
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    <XmlIgnore()> _
    Public ReadOnly Property Active() As Boolean
        Get
            If Not String.IsNullOrEmpty(Me._Active) Then
                If Me._Active.Trim.ToUpper = "TRUE" Then
                    Return True
                End If
            End If
            Return False
        End Get
    End Property

End Class

